<template>
  <a-layout>
    <a-layout-sider v-model:collapsed="collapsed" :trigger="null" collapsible>
      <div class="logo">
        <img src="https://www.surely.cool/surely-vue-logo.png"/>
        后台管理系统
      </div>
      <a-menu 
          v-model:selectedKeys="selectedKeys" 
          theme="dark"
          mode="inline"
          @click="handleMenu">
        <a-menu-item key="/userList">
          <strikethrough-outlined />
          <span>用户管理</span>
        </a-menu-item>
        <a-menu-item key="/categoryList">
          <video-camera-outlined />
          <span>类别管理</span>
        </a-menu-item>
        <a-menu-item key="/goodsList">
          <upload-outlined />
          <span>商品管理</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 5">
        <menu-unfold-outlined
          v-if="collapsed"
          class="trigger"
          @click="() => (collapsed = !collapsed)"
        />
        <menu-fold-outlined v-else class="trigger" @click="() => (collapsed = !collapsed)" />
      </a-layout-header>
      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '580px' }"
      >
        <!-- 二级路由出口 -->
        <router-view></router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script lang="ts">
import {
  StrikethroughOutlined,
  UserOutlined,
  VideoCameraOutlined,
  UploadOutlined,
  MenuUnfoldOutlined,
  MenuFoldOutlined,
} from '@ant-design/icons-vue';
import { defineComponent, ref } from 'vue';
import {useRouter} from 'vue-router'
export default defineComponent({
  components: {
    UserOutlined,
    VideoCameraOutlined,
    UploadOutlined,
    MenuUnfoldOutlined,
    MenuFoldOutlined,
    StrikethroughOutlined
  },
  setup() {
    const router=useRouter()
    const handleMenu=({key}:any)=>{
      console.log('--------------',key);
      router.push(key)
    }
    return {
      selectedKeys: ref<string[]>(['1']),
      collapsed: ref<boolean>(false),
      handleMenu
    };
  },
});
</script>
<style>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.3);
  margin: 16px;
}

.site-layout .site-layout-background {
  background: #fff;
}
.logo{
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  height: 80px;
  line-height:80px;
}
.logo img{
  width: 20px;
  margin:0 20px;
}
</style>